{extend name="common/main"/}

{block name="body"}
    <div class="main-title">
        <h2>
            {present name="data"}[ {$data.title} ] 子{/present}
            菜单管理
        </h2>
    </div>
    <div class="with-padding">

        <div class="button-box row clearfix ">
            <div class="col-xs-10">
                <a class="btn btn-info" href="{:url('edit')}">新增</a>
                <button class="btn btn-danger ajax-post confirm" url="{:url('del')}" target-form="ids">删除</button>
                <a class="btn btn-warning" href="{:url('import')}">导入</a>
                <button class="btn list_sort" url="{:url('sort')}">排序</button>
            </div>
            <!-- 高级搜索 -->
            <div class="col-xs-2">
                <div class="search-form fr cf">
                    <div class="sleft">
                        <div class="input-group">
                            <input type="text" name="title" class="form-control" value="{:input('title')}"
                                   placeholder="请输入菜单名称">
                                   <span class="input-group-btn">
                        <a class="btn btn-default" href="javascript:;" id="search" url="{:url()}">
                            <i class="icon-search"></i>
                        </a></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <form class="ids">
            <table class="table table-bordered table-striped table-hover muu-table">
                <thead>
                <tr>
                    <th class="row-selected">
                        <input type="checkbox" class="check-all" id="check-all">
                    <label for="check-all"></label>
                    </th>
                    <th class="hidden">{:lang('ID')}</th>
                    <th width="300">名称</th>
                    <th width="160">分组</th>
                    <th width="400">URL</th>
                    <th>排序</th>
                    <th>是否隐藏</th>
                    <th>类型</th>
                    <th width="180">操作</th>
                </tr>
                </thead>
            </table>
                
            {notempty name="list"}
            {volist name="list" id="menu"}
            <table class="table table-bordered table-striped table-hover muu-table">
                <tbody>
                    <tr style="background-color: #eee;">
                        <td>
                            <input class="ids" id="menu-{$menu.id}" type="checkbox" name="id[]" value="{$menu.id}">
                            <label for="menu-{$menu.id}"></label>
                        </td>
                        <td class="hidden">
                            {$menu.id}
                        </td>
                        <td class="parent-title" width="300">
                            <span style="font-size: 16px; font-weight: 700;">{$menu.title}</b>
                        </td>
                        <td width="160">
                            {$menu.group}
                        </td>
                        <td width="400">
                            {$menu.url}
                        </td>
                        <td>
                            {$menu.sort}
                        </td>
                        <td>
                            <a href="{:url('toogleHide',['id'=>$menu['id'],'value'=>abs($menu['hide']-1)])}" class="ajax-get">
                                {$menu.hide_str}
                            </a>
                        </td>
                        <td>
                            <a href="#" class="ajax-get">
                                {$menu.type_str}
                            </a>
                        </td>
                        <td width="180" class="text-right">
                            <a title="新增" class="btn btn-sm btn-success" href="{:url('edit',['pid' => $menu['id']])}"> + 新增 </a>
                            <a title="编辑" class="btn btn-sm btn-info" href="{:url('edit',['id' => $menu['id']])}">编辑</a>
                            <a title="删除" class="btn btn-sm btn-danger confirm ajax-get" title="删除" href="{:url('del',['id' => $menu['id']])}">删除</a>
                        </td>
                    </tr>
                    {notempty name="menu._child"}
                    {volist name="menu._child" id="cmenu2"}
                    <tr>
                        <td> 
                            <input class="ids" id="cmenu2-{$menu.id}" type="checkbox" name="id[]" value="{$cmenu2.id}">
                            <label for="cmenu2-{$cmenu2.id}"></label>
                        </td>
                        <td class="hidden">
                            {$cmenu2.id}
                        </td>
                        <td class="top-chile-title">
                            -- <span style="font-weight: 600;">{$cmenu2.title}</span>
                        </td>
                        <td>
                            {$cmenu2.group}
                        </td>
                        <td>
                            {$cmenu2.url}
                        </td>
                        <td>
                            {$cmenu2.sort}
                        </td>
                        <td>
                            <a href="{:url('toogleHide',['id'=>$cmenu2['id'],'value'=>abs($cmenu2['hide']-1)])}" class="ajax-get">
                                {$cmenu2.hide_str}
                            </a>
                        </td>
                        <td>
                            <a href="#" class="ajax-get">
                                {$cmenu2.type_str}
                            </a>
                        </td>
                        <td class="text-right">
                            <a title="新增" class="btn btn-sm btn-success" href="{:url('edit',['pid' => $cmenu2['id']])}"> + 新增 </a>
                            <a title="编辑" class="btn btn-sm btn-info" href="{:url('edit',['id' => $cmenu2['id']])}">编辑</a>
                            <a title="删除" class="btn btn-sm btn-danger confirm ajax-get" title="删除" href="{:url('del',['id' => $cmenu2['id']])}">删除</a>
                        </td>
                    </tr>
                    {notempty name="cmenu2._child"}
                    {volist name="cmenu2._child" id="cmenu3"}
                    <tr>
                        <td>
                            <input class="ids" id="cmenu3-{$cmenu3.id}" type="checkbox" name="id[]" value="{$cmenu3.id}">
                            <label for="cmenu3-{$cmenu3.id}"></label>
                        </td>
                        <td class="hidden">
                            {$cmenu3.id}
                        </td>
                        <td>
                            -------- {$cmenu3.title}
                        </td>
                        <td>
                            {$cmenu3.group}
                        </td>
                        <td>
                            {$cmenu3.url}
                        </td>
                        <td>
                            {$cmenu3.sort}
                        </td>
                        <td>
                            <a href="{:url('toogleHide',['id'=>$cmenu3['id'],'value'=>abs($cmenu3['hide']-1)])}" class="ajax-get">
                                {$cmenu3.hide_str}
                            </a>
                        </td>
                        <td>
                            <a href="#" class="ajax-get">
                                {$cmenu3.type_str}
                            </a>
                        </td>
                        <td class="text-right">
                            <a title="编辑" class="btn btn-sm btn-info" href="{:url('edit',['id' => $cmenu3['id']])}">编辑</a>
                            <a title="删除" data-role="delete" class="btn btn-sm btn-danger confirm ajax-get" title="删除" href="{:url('del',['id' => $cmenu3['id']])}">删除</a>
                        </td>
                    </tr>
                    {/volist}
                    {/notempty}

                    {/volist}
                    {/notempty}
                </tbody>
            </table>
            {/volist}
            {else/}
            <div class="text-center">空空如也~</div>
            {/notempty}
                
        </form>
        <!-- 分页 -->
        <div class="page">

        </div>
    </div>
{/block}

{block name="script"}
    <script type="text/javascript">
        $(function () {
            //搜索功能
            $("#search").click(function () {
                var url = $(this).attr('url');
                var query = $('.search-form').find('input').serialize();
                query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
                query = query.replace(/^&/g, '');
                if (url.indexOf('?') > 0) {
                    url += '&' + query;
                } else {
                    url += '?' + query;
                }
                window.location.href = url;
            });
            //回车搜索
            $(".search-input").keyup(function (e) {
                if (e.keyCode === 13) {
                    $("#search").click();
                    return false;
                }
            });
            //导航高亮

            //点击排序
            $('.list_sort').click(function () {
                var url = $(this).attr('url');
                if (url != undefined && url != '') {
                    window.location.href = url;
                }
            });
        });
    </script>
{/block}